﻿namespace NTLib.Core.UTest.Shared
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using NTLib.Core.Exceptions.Shared;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;

    [TestClass]
    public class SharedObjectUTest
    {
        #region Methods

        [TestCategory("Core.Shared")]
        [TestMethod]
        public void CreateSharedObject()
        {
            SharedTestObject obj = new SharedTestObject();

            Assert.IsNotNull(SharedTestObject.NamePropDp);
            Assert.AreEqual(obj.Name, "Poney");

            OtherSharedTestObject otherObj = new OtherSharedTestObject();

            Assert.IsNotNull(OtherSharedTestObject.IDPropDp);
            Assert.AreEqual(otherObj.ID, 42);
        }


        [TestCategory("Core.Shared")]
        [TestMethod]
        public void SharedAndLocalObject()
        {
            SharedTestObject obj = new SharedTestObject();

            Assert.IsNotNull(SharedTestObject.NamePropDp);
            Assert.AreEqual(obj.Name, "Poney");

            OtherSharedTestObject otherObj = new OtherSharedTestObject();

            Assert.IsNotNull(OtherSharedTestObject.IDPropDp);
            Assert.AreEqual(otherObj.ID, 42);

            SharedTestObject objName = new SharedTestObject();

            obj.Name = "Poney 2";

            Assert.AreEqual(obj.Name, "Poney 2");
            Assert.AreEqual(objName.Name, "Poney");

            Assert.AreEqual(otherObj.ID, 42);

            obj.ClearLocalValue(SharedTestObject.NamePropDp);
            Assert.AreEqual(obj.Name, "Poney");
        }

        [TestCategory("Core.Shared")]
        [TestMethod]
        public void SharedAndLocalObjectError()
        {
            SharedTestObject obj = new SharedTestObject();

            Assert.IsNotNull(SharedTestObject.NamePropDp);
            Assert.AreEqual(obj.Name, "Poney");

            OtherSharedTestObject otherObj = new OtherSharedTestObject();

            Assert.IsNotNull(OtherSharedTestObject.IDPropDp);
            Assert.AreEqual(otherObj.ID, 42);

            SharedTestObject objName = new SharedTestObject();

            obj.Name = "Poney 2";

            Assert.AreEqual(obj.Name, "Poney 2");
            Assert.AreEqual(objName.Name, "Poney");

            Assert.AreEqual(otherObj.ID, 42);

            obj.ClearLocalValue(SharedTestObject.NamePropDp);
            Assert.AreEqual(obj.Name, "Poney");

            try
            {
                obj.SetValue(OtherSharedTestObject.IDPropDp, 24);
            }
            catch (BadSharedPropertyOwnerException)
            {

            }

            try
            {
                otherObj.SetValue(SharedTestObject.NamePropDp, 24);
            }
            catch (BadSharedPropertyOwnerException)
            {

            }
        }

        #endregion
    }
}
